package com.laizhenghua.share.user.api.factory;

import cn.hutool.core.util.StrUtil;
import com.laizhenghua.share.common.core.domain.R;
import com.laizhenghua.share.user.api.RemoteUserService;
import com.laizhenghua.share.user.api.domain.entity.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Description
 * @Author laizh
 * @Date 2025/10/13 21:39
 **/
@Component
public class RemoteUserServiceFallbackFactory implements FallbackFactory<RemoteUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserServiceFallbackFactory.class);
    @Override
    public RemoteUserService create(Throwable cause) {
        log.error("用户服务调用失败: {}", cause.getMessage());
        return new RemoteUserService() {

            @Override
            public R<UserInfo> wxLogin(String code) {
                return R.fail(StrUtil.format("微信登录失败:", cause.getMessage()));
            }

            @Override
            public R<String> wxLogout() {
                return R.fail(StrUtil.format("微信注销失败:", cause.getMessage()));
            }

            @Override
            public R<Boolean> isFreeDeposit() {
                return R.fail("系统繁忙,请稍后再重试!");
            }

            @Override
            public R<UserInfo> getUserInfo(Long id) {
                return R.fail("系统繁忙,请稍后再重试!");
            }
        };
    }
}
